package com.atguigu.daijia.driver.client.fallback;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.driver.client.CosFeignClient;
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @create: 2024/9/21
 * @author: gyhe10
 * @description: CosFeignClient 接口的降级实现类
 **/
@Component
public class CosFeignClientFallbackFactory implements FallbackFactory<CosFeignClient> {
    @Override
    public CosFeignClient create(Throwable cause) {
        return new CosFeignClient() {
            @Override
            public Result<CosUploadVo> upload(MultipartFile file, String path) {
                if (cause instanceof GuiguException) {
                    return Result.build(null, ((GuiguException) cause).getCode(), cause.getMessage());
                } else {
                    return Result.build(null, ResultCodeEnum.FEIGN_FAIL);
                }
            }
        };
    }
}
